package com.buddy.syn.block._09;

/**
 * 当多个线程同时执行synchronized(x){}同步代码块时，呈现同步的效果
 * 前提是 同一个对象监视器
 */
public class Service {

    public void methodA(MyObject myObject){
        synchronized (myObject){
            try {
                System.out.println("methodA ____getLock time="+System.currentTimeMillis()
                        +" run ThreadName="+Thread.currentThread().getName());
                Thread.sleep(2000);
                System.out.println("methodA releaseLock time="+System.currentTimeMillis()
                        +" run ThreadName="+Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
